/**
 * Description:CardAction.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  
 */
package org.paradise.dms.web.action.registerinfo;

import java.util.List;

import org.apache.log4j.Logger;
import org.directwebremoting.annotations.RemoteProxy;
import org.paradise.dms.services.CardService;
import org.paradise.dms.web.action.DMSBaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 
 */
@Service
@RemoteProxy(name = "cardAction")
public class CardAction extends DMSBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4000611726594825502L;

	private static Logger log = Logger.getLogger(CardAction.class);

	@Autowired
	@Qualifier("cardServiceImpl")
	private CardService cardService;

	public CardService getCardService() {
		return cardService;
	}

	public void setCardService(CardService cardService) {
		this.cardService = cardService;
	}

	/**
	 * Description: 通过饭卡的id取得学生学号
	 * @Version1.0 
	 * @param carid 
	 */
	public String getStudentNo(String cardid){
		try{
		String cardids = String.valueOf(Integer.parseInt(cardid,16));
		return this.cardService.getStudentNo(cardids).getIdserial();	
		}catch(Exception e){
			return null;
		}
		
	}
	
	/**
	 * 
	 * Description: 通过饭卡的id取得学生信息
	 * 
	 * @Version1.0 
	 * @param cardid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String[] findStudentByCardid(
			String cardid) {
		try{
			String cardids = String.valueOf(Integer.parseInt(cardid,16));
			List sl = this.cardService.findStudentByCardid(cardids);
			if (0 == sl.size()) {
				return null;
			}
			Object[] slist_id = (Object[]) sl.get(0);

			if (slist_id != null & slist_id.length > 0) {
				String[] strarr = new String[slist_id.length];
				for (int a = 0; a < slist_id.length; a++) {
						if (null == slist_id[a]) {
							strarr[a] = "";
					}
						strarr[a] = slist_id[a]+"";
				}
				return strarr;
			}
			return null;
		} catch (Exception e) {
			log.error("DMS_error:通过饭卡的id取得学生基本信息有误!");
			log.error("错误原因:" + e);
			return null;
		}
	}
}
